<template>
    <div id="from">
            <el-form ref="form" :rules="rules" :model="form" label-width="100px">
                <el-form-item prop="origin" label="始发地：">
                    <el-col :span="7">
                        <el-input v-model="form.Origin"></el-input>
                    </el-col>
                </el-form-item>
                <el-form-item prop="destination" label="目的地：">
                    <el-col :span="7">
                        <el-input v-model="form.Destination"></el-input>
                    </el-col>

                </el-form-item>
                <el-form-item prop="origin" label="重量：">
                    <el-col :span="7">
                        <el-input-number v-model="form.Weight" :min="1" label="描述文字">
                        </el-input-number>
                    </el-col>
                </el-form-item>
                <el-form-item prop="ShippingTime" label="寄件时间：">
                    <el-col :span="7">
                        <el-date-picker v-model="form.ShippingTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
                            placeholder="选择日期时间"></el-date-picker>
                    </el-col>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('form')">查询</el-button>
                    <el-button @click="resetForm('form')">重置</el-button>
                </el-form-item>
            </el-form>
    </div>
</template>

<script>
export default {
    name: "From",
    data() {
        // var origin =(rule, value, callback)=>{

        // }
        return {
            form: {
                Origin: "",
                Destination: "",
                Weight: 0,
                ShippingTime: ""
            },
            rules: {
                origin: [
                    { required: true, message: '请输入始发地', trigger: 'blur' },
                    { min: 3, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                destination: [
                    { required: true, message: '请输入目的地', trigger: 'blur' },
                    { min: 3, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                ShippingTime: [
                    {
                        required: true,
                        message: "请选择日期",
                        trigger: "change",
                    },
                ],
            },
        };
    },
    methods: {
        async submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                console.log(this.form.ShippingTime);
                if (valid) {
                    try {
                        let { res } = await this.$API.reqFreight(this.form)
                        this.$emit('changeres', res)
                    } catch (error) { }
                } else {
                    console.log('输入有误');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        }
    }
};
</script>

<style lang="scss" scoped>

</style>
